<?php
require_once("levelView.php");
require_once(CORE_DIR.'levelModel.php');
require_once(CORE_DIR.'taskpointModel.php');
require_once(CORE_DIR.'userModel.php');

class getAction extends authAction{

	function __construct(){
		$this->view = new levelView();
	}

	public function run($get, $post, $viewtype) {
		parent::run($get,$post,$viewtype);
		
		$lModel = new levelModel();
		$tpModel = new taskpointModel();
		$uModel = new userModel();

		$userId = null;
		$levels = null;
		$levels1Upper = null;
		$currentPoints = null;
		
		if (isset($get["level"])){
			$level = $get["level"];
			
			if(isset($get["pointTypeId"]))
			{
				$pointTypeId = isset($get["pointTypeId"]);
				$levels = $lModel->getLevelByPointTypeId($level, $pointTypeId);
				$levels1Upper = $lModel->getLevelByPointTypeId($level+1, $pointTypeId);
			}			
			else
			{
				$levels = $lModel->getLevelById($level);
				$levels1Upper = $lModel->getLevelById($level + 1);
			}
		}
		else
		{
			$levels = $lModel->getAllLevels();	
		}
		
		if (isset($get["userId"])){
			$userId = $get["userId"];
		}		
		else 
		{
			$userDto = $uModel->getActiveUser();
			$userId = $userDto->getId(); 
		}
		
		$currentPoints = $tpModel->getUserPoints($userId);
		
		$this->view->setProperty("levels", $levels);
		$this->view->setProperty("levels1upper", $levels1Upper);
		$this->view->setProperty("currPoints", $currentPoints);
		$this->view->showGetLevel();
			
	}
}
?>